// components/booking-card/booking-card.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    // 预约数据
    bookingData: {
      type: Object,
      value: {}
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    // 组件内部使用的显示数据
    id:'',
    consultTypeText: '',
    statusText: '',
    statusClass: '',
    startTime: '',
    endTime: '',
    duration: '',
    consultDate: '',
    consultantName: '',
    consultCountText: '',
    calculatedStatus: '',
    consultAdvice: '',
    consultFeedback: '',
    problemDesc: '',
    remark: ''
  },

  /**
   * 组件的方法列表
   */
  methods: {

  },

  lifetimes: {
    attached() {
      // 组件挂载时处理数据
      this.processData();
    }
  },

  observers: {
    'bookingData': function(bookingData) {
      // 监听数据变化
      // console.log('组件收到数据:', bookingData);
      this.processData();
    }
  },

  methods: {
    processData() {
      const { bookingData } = this.properties;
      console.log('处理预约数据:', bookingData);
      
      if (!bookingData) {
        console.log('预约数据为空');
        return;
      }

      // 直接使用从父组件传递过来的处理好的数据
      const displayData = {
        id:bookingData.id,
        consultTypeText: bookingData.consultTypeText || '未知类型',
        statusText: bookingData.statusText || '未知',
        statusClass: bookingData.statusClass || 'unknown',
        startTime: bookingData.startTime || '--:--',
        endTime: bookingData.endTime || '--:--',
        duration: bookingData.duration || '0',
        consultDate: bookingData.consultDate || '未知日期',
        consultantName: bookingData.consultantName || '老师',
        teacherAvatar:bookingData.consultantAvatar || '',
        consultantIntroduction: bookingData.consultantIntroduction || '<p>暂无介绍</p>',
        calculatedStatus: bookingData.calculatedStatus || 'unknown',
        consultAdvice: bookingData.consultAdvice || '',
        consultFeedback: bookingData.consultFeedback || '',
        problemDesc: bookingData.problemDesc || '',
        remark: bookingData.remark || ''
      };

      // 处理咨询人数显示文本
      let consultCountText = '';
      if (bookingData.consultCount !== undefined && bookingData.consultCount !== null) {
        consultCountText = `${bookingData.consultCount}人咨询过`;
      } else if (bookingData.recordNo) {
        consultCountText = `预约号: ${bookingData.recordNo}`;
      } else {
        consultCountText = '';
      }
      displayData.consultCountText = consultCountText;

      console.log('组件显示数据:', displayData);
      
      this.setData(displayData);
    }
  }
})